package org.tln.db137.service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.tln.db137.mapper.RolemenuMapper;
import org.tln.db137.entity.Rolemenu;
@Service
public class RolemenuService extends ServiceImpl<RolemenuMapper, Rolemenu> {

    public boolean updateRoleMenuid(int roleid, List<Integer> listMenu) {
        //1.根据角色id删除这个角色的所有菜单
        UpdateWrapper<Rolemenu> objectUpdateWrapper = new UpdateWrapper<>();
        objectUpdateWrapper.eq("roleid", roleid);
        this.baseMapper.delete(objectUpdateWrapper);
        //2.根据角色id增加对应的菜单
        for (Integer menuid : listMenu) {
            Rolemenu rolemenu = new Rolemenu();
            rolemenu.setRoleid(roleid);
            rolemenu.setMenuid(menuid);
            this.baseMapper.insert(rolemenu);
        }

        return true;
    }
}
